package com.kaifamiao.tree;

import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;

public class NavigableMapTest {

	public static void main(String[] args) {
		
		Map<String,Integer> a = Map.of( "红烧肉" , 20 , "盐煎肉" , 14 , "回锅肉" , 16 , "小炒肉" , 18 );
		Map<String,Integer> b = Map.of( "老碗鱼" , 80 , "葫芦头" , 30 , "红绕肥肠" , 25 , "刺身肥肠" , 28 );
		
		NavigableMap<String,Integer> nm = new TreeMap<>();
		nm.putAll( a );
		nm.putAll( b );
		System.out.println( nm );
		
		Map.Entry<String,Integer> first = nm.pollFirstEntry();
		System.out.println( first );
		System.out.println( nm );
		
		Map.Entry<String,Integer> last = nm.pollLastEntry();
		System.out.println( last );
		System.out.println( nm );
		
		first = nm.firstEntry();
		System.out.println( first );
		System.out.println( nm );
		
		last = nm.lastEntry();
		System.out.println( last );
		System.out.println( nm );
		
		Map.Entry<String,Integer> higher = nm.higherEntry( "红烧肉" );
		System.out.println( higher );
		
	}

}
